package com.game.model;

import com.game.interfaces.Blast;
import com.game.util.ImageUtil;
import com.game.util.PropertiesUtil;

import java.awt.*;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 子弹爆炸类
 *
 * @author: tjc
 * @Date: 2019-5-4
 */
public class BulletBlast extends Blast {

    private int step = 5;

    private AtomicBoolean alive = new AtomicBoolean(false);

    public BulletBlast(int localX, int localY) {
        this.localX = localX;
        this.localY = localY;
        this.SIZE_X = PropertiesUtil.loadInt("bulletBlast.width");
        this.SIZE_Y = PropertiesUtil.loadInt("bulletBlast.length");
    }

    public void init(){
        alive.set(true);
    }
    public void destroy(){
        alive.set(false);
    }

    @Override
    public void draw(Graphics g) {
        if (step <= 0) {
            this.destroy();
        }
        g.drawImage(ImageUtil.bulletBlastImages[step--], localX, localY, SIZE_X, SIZE_Y, null);
    }

    @Override
    public boolean alive() {
        return alive.get();
    }
}
